﻿<%@ Page EnableEventValidation="false" Title="" ValidateRequest="false" Language="C#" MasterPageFile="~/Site1.master"
    AutoEventWireup="True" Inherits="IndoTradingMemberV2.product_new2"
    CodeBehind="new2.aspx.cs" %>

<%@ Register Assembly="MREDKJNumericBox" Namespace="MREDKJ" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="/assets/jquery-ui/jquery-ui-1.10.1.custom.min.css" type="text/css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="/js/uploader/ajaxupload.js"></script>
    <link href="/scripts/Default/fancybox/jquery.fancybox-1.3.4.css" rel="Stylesheet"
        type="text/css" />
    <script type="text/javascript" src="/scripts/Default/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
    <div class="portlet box red">
        <div class="portlet-title">
            <h4><i class="icon-bar-chart"></i>
                <%= Resources.Language.NewProduct %>
            </h4>
        </div>
        <div class="portlet-body">
            <br />
            <asp:Literal ID="litMsg" runat="server"></asp:Literal>
            <div id="postStepStatus" class="dpl-steps clearfix" style="width: 480px; float: left;">
                <div class="step first ">
                    <span class="s-1">1</span> <span class="s-2">
                        <%=Resources.Language.ChooseProductCategory %></span> <span class="s-3"></span>
                </div>
                <div class="step current">
                    <span class="s-1">2</span> <span class="s-2">
                        <%=Resources.Language.FillProductDetails %></span> <span class="s-3"></span>
                </div>
                <div class="step last">
                    <span class="s-1">3</span> <span class="s-2">
                        <%=Resources.Language.AwaitingApproval %></span> <span class="s-3"></span>
                </div>
            </div>
            <br style="clear: both" />


            <div class="control-group">
                <div class="buttonfield">
                    <asp:Button runat="server" ID="btnNext3" CssClass="button" OnClick="btnNext_Click"
                        Text="<%$ Resources:Language,Save %>" />
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>Product ID</b>
                </label>
                <div class="controls">
                    <%=sProdID %>
                </div>
            </div>
            <%if (oProd.Category != null)
              { %>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%= Resources.Language.Categories %></b>
                </label>
                <div class="controls">
                    <%=oProd.Category.Name %>
                    <asp:Literal ID="ltrChangeCategory" runat="server"></asp:Literal>
                </div>
            </div>
            <%} %>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.ProductNameIndo%><font color="red">(*)</font></b>
                </label>
                <div class="controls">
                    <asp:TextBox ID="txtNama" runat="server" Width="400" Columns="50" MaxLength="128" EnableViewState="false"></asp:TextBox>
                    <a href="javascript:void(0);" onclick="return overlib('<%=Resources.Language.FillProductNameInd %>',STICKY,CAPTION,'<%=Resources.Language.ProductNameIndo%>');"
                        onmouseout="return nd();">
                        <img src="/images/question.gif" /></a>
                    <asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txtNama"
                        ErrorMessage="<%$ Resources:Language, FillProductNameInd %>" SetFocusOnError="true"
                        Font-Bold="true" ForeColor="Red" EnableClientScript="false"></asp:RequiredFieldValidator>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.ProductNameEng%><font color="red">(*)</font></b>
                </label>
                <div class="controls">
                    <asp:TextBox ID="txtNamaEng" Width="400" runat="server" Columns="50" MaxLength="128" EnableViewState="false"></asp:TextBox>
                    <a href="javascript:void(0);" onclick="return overlib('<%=Resources.Language.FillProductNameEng %>',STICKY,CAPTION,'<%=Resources.Language.ProductNameEng%>');"
                        onmouseout="return nd();">
                        <img src="/images/question.gif" /></a>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtNamaEng"
                        ErrorMessage="<%$ Resources:Language, FillProductNameEng %>" SetFocusOnError="true"
                        Font-Bold="true" ForeColor="Red" EnableClientScript="false"></asp:RequiredFieldValidator>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.OtherProductName%><font color="red">(*)</font></b>
                </label>
                <div class="controls">
                    <asp:TextBox ID="txtOtherName" runat="server" Columns="50" MaxLength="128" EnableViewState="false"></asp:TextBox>
                    <a href="javascript:void(0);" onclick="return overlib('<%=Resources.Language.FillOtherProductName %>',STICKY,CAPTION,'<%=Resources.Language.OtherProductName%>');"
                        onmouseout="return nd();">
                        <img src="/images/question.gif" /></a>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtOtherName"
                        ErrorMessage="<%$ Resources:Language, FillOtherProductName %>" SetFocusOnError="true"
                        Font-Bold="true" ForeColor="Red" EnableClientScript="false"></asp:RequiredFieldValidator>
                </div>
            </div>
            
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.CountryOrigin%><font color="red">(*)</font></b>
                </label>
                <div class="controls">
                    <asp:DropDownList ID="ddlCountry" runat="server">
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddlCountry"
                        ErrorMessage="<%$ Resources:Language, ChooseCountry %>" SetFocusOnError="true"
                        Font-Bold="true" ForeColor="Red" EnableClientScript="false"></asp:RequiredFieldValidator>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.ProductGroup%><font color="red">(*)</font>
                    </b>
                </label>
                <div class="controls">
                    <asp:HiddenField ID="hfGroupProduct" runat="server" ClientIDMode="Static"></asp:HiddenField>
                    <span id="parentSpan" runat="server">
                        <asp:DropDownList ID="ddlGroupParent" runat="server" ClientIDMode="Static"></asp:DropDownList>  <a href="addproductgroup.aspx?q=<%=sq2.ToString() %>" id="aTambah" name="aTambah">
                        <%=Resources.Language.AddProductGroup%></a> <a href="javascript:void(0);" onclick="return overlib('<%=Resources.Language.GroupProduct %>',STICKY,CAPTION,'<%=Resources.Language.ProductGroup%>',CENTER);"
                            onmouseout="return nd();">
                            <img src="/images/question.gif" /></a><br />
                    </span>
                    <asp:DropDownList ID="ddlGroupProduct" runat="server" ClientIDMode="Static">
                    </asp:DropDownList>
                   
                    <br />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="<%$Resources:Language,ReqGroupProduct %>" ControlToValidate="ddlGroupParent" Display="Dynamic" SetFocusOnError="true" ForeColor="Red"
                        Font-Bold="true" EnableClientScript="false"></asp:RequiredFieldValidator>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b><%if(oComp.IsExportCompany != null && oComp.IsExportCompany){ %>F.O.B

                        <%} %> 
                        <%=Resources.Language.Price%><font color="red">(*)</font></b>
                </label>
                <div class="controls">

                    <asp:DropDownList ID="ddlCurrency" runat="server" Width="90px">
                      
                    </asp:DropDownList>
                    <cc1:NumericTextBox ID="txtPrice" runat="server" allowdecimal="true" Width="100px"></cc1:NumericTextBox>
                    /
                 <asp:TextBox ID="txtUnitPrice" runat="server" Columns="10" Text="Unit" Width="70px"></asp:TextBox>
                    e.g
                <%=Resources.Language.unit %>
                    <a href="javascript:void(0);" onclick="return overlib('<%=Resources.Language.FillPrice0 %>',STICKY,CAPTION,'<%=Resources.Language.Price%>');"
                        onmouseout="return nd();">
                        <img src="/images/question.gif" /></a>
                    <asp:RequiredFieldValidator ID="rfvPrice" runat="server" ControlToValidate="txtPrice"
                        ErrorMessage="<%$Resources:Language,FillPrice0 %>" SetFocusOnError="true" ForeColor="Red"
                        Font-Bold="true" EnableClientScript="false" Display="Dynamic"></asp:RequiredFieldValidator>
                </div>
            </div>

            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.Weight%>
                    </b>
                </label>
                <div class="controls">
                    <asp:DropDownList ID="ddlWeight" runat="server" Width="150px">
                        <asp:ListItem Text="Gram (g)" ID="gram"></asp:ListItem>
                        <asp:ListItem Text="Kilogram (kg)" ID="kilogram"></asp:ListItem>
                    </asp:DropDownList>

                     <cc1:NumericTextBox ID="txtWeight" runat="server" allowdecimal="true" Width="150px"></cc1:NumericTextBox>
                </div>
            </div>

            <div class="control-group">
                <label class="control-label">
                    <b>Minimum Order</b>
                </label>
                <div class="controls">
                    <cc1:CurrencyTextBox ID="txtMOQ" runat="server" allowdecimal="true"></cc1:CurrencyTextBox>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b><%=Resources.Language.Brand %></b>
                </label>
                <div class="controls">
                    <asp:TextBox ID="txtBrand" runat="server"></asp:TextBox>
                    <% Page.ClientScript.RegisterStartupScript(GetType(), "autocomplete-brand", @"
$(function() {
    var cache = {};
    $( ""#" + txtBrand.ClientID + @""" ).autocomplete({
      minLength: 2,
      source: function( request, response ) {
        var term = request.term;
        if ( term in cache ) {
          response( cache[ term ] );
          return;
        }
		$.ajax({
			url: '/ajaxmethod.asmx/SearchBrand',
			dataType: 'json',
			data:JSON.stringify(request),
			cache: false,
			type: 'POST',
			contentType: 'application/json; charset=utf-8',
			success: function(doc) {
				cache[ term ] = doc.d;
				response( doc.d );
			}
		});
      }
    });
  });", true); %>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>SKU</b>
                </label>
                <div class="controls">
                    <asp:TextBox ID="txtSku" runat="server" Columns="50" MaxLength="128" EnableViewState="false"></asp:TextBox>
                    <br />
                    <font size="1" color="red"><%=Resources.Language.SKUDesc %></font>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.Photo%></b><br />
                </label>
                <div class="controls">
                    <div id="upload">
                        <span>
                            <%=Resources.Language.ChoosePhoto%></span>
                    </div>
                    <img src="/images/loading.gif" alt="" id="loading" style="display: none" />
                    <span id="status"></span>
                    <%= Resources.Language.MaxDisplayImg%>
                (480 x 640) pixel<br />
                    <div id="photos">
                    </div>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.DescriptionInd %><font color="red">(*)</font></b> <a href="javascript:void(0);" onclick="return overlib('<%=Resources.Language.FillDescriptionInd %>',STICKY,CAPTION,'<%=Resources.Language.DescriptionInd %>');"
                            onmouseout="return nd();">
                            <img src="/images/question.gif" /></a>
                    <br />
                    <br />
                    <br />
                    <a href='http://translate.google.com' target="_blank">[<%= Resources.Language.HelpTranslation %>]</a>
                    <br />
                    <br />
                    <input type="button" id="idInsertImageDetilInd" value='<%= Resources.Language.InsertImage %>' class="btnControl" />
                </label>
                <div class="controls">
                    <textarea class="ckeditor" cols="80" id="txtDetilIndo1" name="txtDetilIndo1" rows="10" runat="server"></textarea>
                    <asp:RequiredFieldValidator ID="rfvDetilIndo" runat="server" ControlToValidate="txtDetilIndo1"
                        EnableClientScript="false" ForeColor="Red" ErrorMessage="<%$ Resources:Language,FillDescriptionInd %>"></asp:RequiredFieldValidator>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.DescriptionEng %><font color="red">(*)</font></b> <a style="clear: both" href="javascript:void(0);"
                            onclick="return overlib('<%=Resources.Language.FillDescriptionEng %>',STICKY,CAPTION,'<%=Resources.Language.DescriptionEng %>');"
                            onmouseout="return nd();">
                            <img src="/images/question.gif" /></a>
                    <br />
                    <br />
                    <br />
                    <a href='http://translate.google.com' target="_blank">[<%= Resources.Language.HelpTranslation %>]</a>
                    <br />
                    <br />
                    <input type="button" id="idInsertImageDetilEng" value='<%= Resources.Language.InsertImage %>' class="btnControl" />
                </label>
                <div class="controls">
                    <textarea class="ckeditor" cols="80" id="txtDetilEng1" name="txtDetilEng1" rows="10" runat="server"></textarea>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtDetilEng1"
                        EnableClientScript="false" ForeColor="Red" ErrorMessage="<%$ Resources:Language,FillDescriptionEng %>"></asp:RequiredFieldValidator>
                </div>
            </div>
            <div class="control-group">

                <asp:Button ID="btnNext" runat="server" Text="<%$ Resources:Language,Save %>" CssClass="button"
                    OnClick="btnNext_Click" />

                <input type="hidden" id="CoID" value='<%=IndoTradingLib.Utils.Cookie.CompanyID %>' />
            </div>


            <script type="text/javascript" src="/js/overlib_mini.js"></script>
            <script type="text/javascript" src="/js/currency.js"></script>
            <script type="text/javascript">
                function makeSublist(parent, child, isSubselectOptional, childVal) {

                    $("body").append("<select style='display:none' id='" + parent + child + "'></select>");
                    $('#' + parent + child).html($("#" + child + " option"));
                    var parentValue = $('#' + parent).attr('value');
                    if (isSubselectOptional) $('#' + child).prepend("<option value='none'> --- </option>");
                    $('#' + child).html($('#' + child + " option").add($("#" + parent + child + " .sub_" + parentValue).clone()));
                    childVal = (typeof childVal == "undefined") ? "" : childVal;
                    $("#" + child).find('option[value="' + childVal + '"]').attr("selected", true);
                    $('#' + parent).change(
                    function () {
                        var parentValue = $('#' + parent).attr('value');
                        $('#' + child).html($("#" + parent + child + " .sub_" + parentValue).clone());
                        if (isSubselectOptional) $('#' + child).prepend("<option value='none'> --- </option>");
                        $('#' + child).trigger("change");
                        if ($('#' + child + ' option').length > 0) {
                            $('#' + child).css("display", "");
                        }
                        else {
                            //$('#' + child).css("display", "none");
                        }
                        $('#' + child).focus();
                    }
                );
                }
                $(function () { makeSublist('<%=ddlGroupParent.ClientID%>', '<%=ddlGroupProduct.ClientID%>', true, ''); });
                function CloseDialog() {
                    $.fancybox.close();
                    //window.location = '<%= Request.RawUrl %>';
                }

                function Count(text, long) {

                    var maxlength = new Number(long);
                    if (text.value.length > maxlength) {
                        text.value = text.value.substring(0, maxlength);

                    }
                }

                $(document).ready(function () {
                    $("#aTambah").fancybox({
                        'type': 'iframe',
                        'width': 600,
                        'height': 600,
                        onClosed: function () {
                            $("#<%= ddlGroupParent.ClientID %>").empty();
                            $("#<%= ddlGroupParent.ClientID %>").append("<option>Loading......</option>");

                            $.ajax({
                                type: "POST",
                                url: "/AjaxMethod.asmx/GetCompanyProductGroup",
                                data: "{'CompanyID': '" + $("#CoID").val() + "'}",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (response) {
                                    var groups = response.d;
                                    var bval = $("#<%= ddlGroupProduct.ClientID %>").val();
                                    var bval2 = $("#<%= ddlGroupParent.ClientID %>").val();
                                    $("#<%= ddlGroupParent.ClientID+ddlGroupProduct.ClientID %>").empty();
                                    $("#<%= ddlGroupParent.ClientID %>").empty();
                                    $.each(groups, function (index, group) {
                                     
                                        if (!group.IsChild) {
                                            if (index == groups.length - 1 && bval2 == "") {
                                                $("#<%= ddlGroupParent.ClientID %>").append("<option selected value ='" + group.GroupID + "'>" + group.GroupName + "</option>");
                                            }
                                            else if (bval2 != "" && group.GroupID == bval) {
                                                $("#<%= ddlGroupParent.ClientID %>").append("<option selected value ='" + group.GroupID + "'>" + group.GroupName + "</option>");
                                            }
                                            else {
                                                $("#<%= ddlGroupParent.ClientID %>").append("<option value ='" + group.GroupID + "'>" + group.GroupName + "</option>");
                                            }
                                    } else {
                                        if (group.ParentID == null) {
                                            strcpar = '';
                                        } else strcpar = group.ParentID;

                                        if (index == groups.length - 1 && bval == "") {
                                            $("#<%= ddlGroupParent.ClientID+ddlGroupProduct.ClientID %>").append("<option class='sub_" + strcpar + "' selected value ='" + group.GroupID + "'>" + group.GroupName + "</option>");
                                        }
                                        else if (bval != "" && group.GroupID == bval) {
                                            $("#<%= ddlGroupParent.ClientID+ddlGroupProduct.ClientID %>").append("<option class='sub_" + strcpar + "' selected value ='" + group.GroupID + "'>" + group.GroupName + "</option>");
                                        }
                                        else {
                                            $("#<%= ddlGroupParent.ClientID+ddlGroupProduct.ClientID %>").append("<option class='sub_" + strcpar + "'  value ='" + group.GroupID + "'>" + group.GroupName + "</option>");
                                        }

                                }


                                    });
                                    //$('#<%= ddlGroupParent.ClientID+ddlGroupProduct.ClientID %>').html($("#<%= ddlGroupParent.ClientID %> option"));
                                    $('#<%=ddlGroupProduct.ClientID%>').html($("#<%= ddlGroupParent.ClientID+ddlGroupProduct.ClientID %> .sub_" + $("#<%= ddlGroupParent.ClientID %>").val()).clone());
                                    $("#hfGroupProduct").val($("#<%= ddlGroupProduct.ClientID %>").val());
                                },
                                failure: function (msg) {
                                    alert(msg);
                                    $("#<%= ddlGroupProduct.ClientID %>").empty();
                                    $("#<%= ddlGroupParent.ClientID %>").empty();
                                }
                            });
                        }
                    });

                    loadPhotos();
                    $(".btnDelete").live('click', function () {
                        if (window.confirm("<%=Resources.Language.DeleteFoto %>")) {
                            $.ajax({
                                type: "POST",
                                url: '/product/photo.aspx?q=<%=sQuery%>',
                                data: { cmd: "del", id: $(this).attr('rel') },
                                success: function (response) {
                                    $('#photos').html(response);
                                },
                                failure: function (msg) {
                                    alert(msg);
                                }
                            });
                        }
                    });

                    $("#<%= ddlGroupProduct.ClientID%>").change(function () {
                        $("#hfGroupProduct").val($("#<%= ddlGroupProduct.ClientID%>").val());
                    });

                });


            </script>
            <script type="text/javascript">

                $(document).ready(function () {

                    CKEDITOR.replace('<%=txtDetilIndo1.UniqueID%>', {
                        extraPlugins: 'autogrow',
                        removePlugins: 'resize',
                    });

                    CKEDITOR.replace('<%=txtDetilEng1.UniqueID%>', {
                        extraPlugins: 'autogrow',
                        removePlugins: 'resize'
                    });
                    CKEDITOR.instances['<%=txtDetilIndo1.ClientID%>'].on('contentDom', function () {
                        this.document.on('click', function (event) {
                            //my code

                            if (CKEDITOR.instances['<%=txtDetilIndo1.ClientID%>'].getData().toLowerCase().indexOf("isi deskripsi produk anda") >= 0) {
                                CKEDITOR.instances['<%=txtDetilIndo1.ClientID%>'].setData('');
                            }

                        });
                    });
                    CKEDITOR.instances['<%=txtDetilEng1.ClientID%>'].on('contentDom', function () {
                        this.document.on('click', function (event) {

                            if (CKEDITOR.instances['<%=txtDetilEng1.ClientID%>'].getData().toLowerCase().indexOf("fill product description") >= 0) {
                                CKEDITOR.instances['<%=txtDetilEng1.ClientID%>'].setData('');
                            }
                        });
                    });
                    $('#idInsertImageDetilInd').fancybox({
                        'href': '/product/photogallery.aspx?q=<%=sq.ToString()%>&lang=id',
                        'type': 'iframe',
                        'width': 420,
                        'height': 600
                    });
                    $('#idInsertImageDetilEng').fancybox({
                        'href': '/product/photogallery.aspx?q=<%=sq.ToString()%>&lang=en',
                        'type': 'iframe',
                        'width': 420,
                        'height': 600
                    });
                });
            </script>
            <script type="text/javascript">
                $(function () {
                    var btnUpload = $('#upload');
                    var loading = $('#loading');
                    var status = $('#status');

                    new AjaxUpload(btnUpload, {
                        action: '/product/uploader.ashx?q=<%=sQuery%>',
                        name: 'uploadfile',
                        onSubmit: function (file, ext) {
                            if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {
                                status.text('Only JPG, PNG or GIF files are allowed');
                                return false;
                            }

                            btnUpload.hide();
                            loading.show();
                        },
                        onComplete: function (file, response) {
                            status.html('');
                            loading.hide();
                            btnUpload.show();

                            var result = $.parseJSON(response);
                            if (result.IsSuccess) {
                                loadPhotos();
                                status.html(result.Message);
                            } else {
                                status.html(response);
                            }
                        }
                    });
                });

                function loadPhotos() {
                    $.get('/product/photo.aspx?q=<%=sQuery%>', function (data) {
                        if (data != 'empty') {
                            $('#photos').html(data);
                        }
                    });
                }

                function insertImgToDetilInd(data) {
                    var img = '<img src="' + data + '" />';
                    CKEDITOR.instances['<%=txtDetilIndo1.ClientID%>'].insertHtml(img);
                    $.fancybox.close();
                }
                function insertImgToDetilEng(data) {
                    var img = '<img src="' + data + '" />';
                    CKEDITOR.instances['<%=txtDetilEng1.ClientID%>'].insertHtml(img);
                    $.fancybox.close();
                }

            </script>
            <asp:Literal ID="ltrFancyBox" runat="server"></asp:Literal>
        </div>
    </div>

</asp:Content>
